﻿/**
 * 我的月度汇报-编辑KPI 页面 编辑KPI 编辑关键工作计划
 */

var pageData = {}, // 整个页面数据
    curKpiItem, // 当前编辑的kpi数据
    saveRule = {},
    evtHandler = {},
    curListIndex = 0,// 当前查看项在总列表中的index
    mScroll,
    pullOffset = 70,
    pullDown=false,
    pullUp=false,
    maxListIndex,
    maxEwnListIndex,
    curItemType,
    report_date="",
    params = {};
var statuses="";
function init (){
	initScroll();
	$("#leftSide").hide();
	ClearOkPf();
    // 解析url,获取汇报日期
    /*
	 * var url = location.href.split('?')[1]; if(url!=null){ var arr =
	 * url.split('&'); for(var i = 0 ; i < arr.length;i++){ var temp = arr[i];
	 * var tempArr = temp.split('='); var key = tempArr[0]; if(key ==
	 * "report_date"){ report_date=tempArr[1]; } } }
	 */
	report_date = getQueryParam("report_date");
    if(report_date==""){
    	var date = new Date();
		var month = date.getMonth()+1;
		var day = date.getDate();
		var year=date.getFullYear();
		if(day<10){
			if(month==1){
				month=12;
				year = year-1;
			}else
				month=month-1;
		}
		if(month<10)
			month="0"+month;
		report_date = year+"/"+month;
    	$("#bdate").attr("value",report_date);
    	// report_date = date.getFullYear()+"/"+formatDate(date.getMonth()+1);
    }
    loadPageData(report_date);
    bindEvent();
    timeoutListener(); // 页面时间超时10分钟
}
function initScroll (){
	if(mScroll instanceof iScroll){
		mScroll.destroy();
	}
	var winH = $(window).height();
	$("#wrap").height(winH);
	var contentHeight=winH-$("#content-main").find("header").height()-$("div.footer-fixed").height();
	
    $("#contentMain").height(contentHeight);
    mScroll = new iScroll("contentMain", {
        vScrollbar:false,
        topOffset:pullOffset,
        onScrollMove:function(){
	        pullDown = (this.y>pullOffset) ? true : false;
	        if(this.maxScrollY>-pullOffset){
	        	pullUp = (this.y<(this.maxScrollY-pullOffset)&&this.y<-pullOffset*3) ? true : false;
	        }else{
	        	pullUp = (this.y<(this.maxScrollY-pullOffset*3)) ? true : false;
	        }
	    },
	    onScrollEnd:function(){
	    	//上下拉  关闭软键盘
	    	var ua = navigator.userAgent;
			if(ua.indexOf("iPhone")>=0){
			}else{
				window.pa_app.closeKeyboard();
			}
	        if(pullDown){
	            renderPreItem();
	        }
	        if(pullUp){
	            renderNextItem();
	            pullUp=false;
	        }
	    }
    });
    mScroll.refresh();
}

// 上拉显示
function renderPreItem(){
		if($("#status").val()=="CO" && $("#app").val()=="0"){
		}else{
			Textyz();
			evtHandler.saveNoyz("N");
		}
	    var preNode = $('div[list-index="'+(curListIndex-1)+'"]');
    	if(preNode.length>0){
	        preNode.trigger("tap");
	    }else{
	        autoClosePrompt("已经是第一条了",null);
	    }
}

// 下拉显示
function renderNextItem(){
		if($("#status").val()=="CO" && $("#app").val()=="0"){
		}else{
			Textyz();
			evtHandler.saveNoyz("N");	
		}
		var preNode = $('div[list-index="'+(curListIndex+1)+'"]');
	    if(preNode.length>0){
	        preNode.trigger("tap");
	    }else{
	        autoClosePrompt("已经是最后一条了",null);
	    }
	    
}

/**
 * 初始化事件绑定
 */
function bindEvent () {
    initEvent();
    evtHandler.handleEvent = function (e){
        var node = $(e.target), et;
        e.preventDefault();
        et = node.attr("et");
        if(!et){
            node = node.parent(), et = node.attr("et");
            if(!et){
                return;
            }
        }
        e.stopPropagation();
        if(et.indexOf(e.type) == 0){
            evtHandler[et.split(":")[1]](node);
        }
    };
    $("#wrap").on("tap change input click keyup", evtHandler.handleEvent);
}
/**
 * 定义所有事件
 */
function initEvent () {
    $('#bdate').scroller('destroy').scroller({
		preset: 'date',
		dateFormat: 'yy/mm',
		dateOrder: 'yymm',
		minDate: new Date(2002, 3, 10, 9, 22),
		maxDate: new Date(2030, 7, 30, 15, 44),
		theme: 'ios',
		mode: 'scroller',
		lang: 'zh',
		display: 'bottom',
		animate: 'slideup'
	});

   // 左右滑动事件
    $("#contentMain").on("swipeRight", function(event){
        event.preventDefault();
        /*
    	//安卓关闭键盘
		var ua = navigator.userAgent;
		if(ua.indexOf("iPhone")>=0){
		}else{
			window.pa_app.closeKeyboard();
		}
		setTimeout(function(){
        	openLeftSide();
        },200);
        */
        openLeftSide();
    }).on("swipeLeft", function(event){
        event.preventDefault();
        closeLeftSide();
    });
    $("#leftSide").on("swipeLeft", function(event){
        event.preventDefault();
        closeLeftSide();
    });

    evtHandler.toggleLeftSide = function(){
        if($("#wrap").hasClass("open-side")){
            closeLeftSide();
        }else{
        	/*
        	//安卓关闭键盘
			var ua = navigator.userAgent;
			if(ua.indexOf("iPhone")>=0){
			}else{
				window.pa_app.closeKeyboard();
			}
			setTimeout(function(){
          	  openLeftSide();
          	},200);
          	*/
          	openLeftSide();
        }
    }
    
    // 汇报状态提示
    $("#statusNode").on("tap",function(){
    	var status = pageData.report.pAIC_MON_STATUS;
    	var manager1_name = pageData.report.manager1_name;
    	var month="";
    	month = report_date.substr(5,2);
    	var message="";
    	if(status=="USUB")
    		message="您的"+month+"月汇报还未提交，提交后将由"+manager1_name+"审批。";
    	else if(status=="SUBM")
    		message="您的"+month+"月汇报已提交，将由"+manager1_name+"确认。";
    	else if(status=="APP")
    		message="您的"+month+"月汇报已由"+manager1_name+"确认。";
    	else if(status=="BAC")
    		message="您的"+month+"月汇报已被"+manager1_name+"驳回，重新提交后将由"+manager1_name+"审批";
    	else if(status=="NON")
    		message="您的"+month+"月汇报还未制定，制定后将由"+manager1_name+"审批。";
    	errorMask(message);
    });
    
    $("#errorMask").tap(function(){
		$("#errorMask").hide();
	});

    // 编辑本月完成
	    var  showNode= $("#TowdoneText") ,noteText,editNode,val,pLi, show;
    evtHandler.handleEdit = function(node){
	$("#doneText").css("height","");
        pLi = node.parent().parent(),
            editNode = pLi.find("textarea");
        pLi.toggleClass("edit-enable");
        if(pLi.hasClass("edit-enable")){
        	node.html(node.html().replace(/<br>/g,"\n"))
            editNode.val(node.text());
//        	var value = this.value;  
//    		// this.selectionStart = this.value.length;
//    		var aCtrl = document.getElementById("text");  
//    		setTimeout(function() { 
//    			aCtrl.setSelectionRange(value.length, value.length); // 将光标定位在textarea的开头，需要定位到其他位置的请自行修改
//    			aCtrl.focus(); 
//    		}, 0); 
            node.text("");
            
            //点击查看文本内容重新计算页面高度
//        	var winH = $(window).height();
//        	$("#wrap").height(winH);
//        	var contentHeight=winH-$("#content-main").find("header").height()-$("div.footer-fixed").height(); 
//            $("#contentMain").height(contentHeight); 
            mScroll.refresh();
        }else{
        	show= node.parent().parent().find(".info-list-cont");
        	showNode.text(editNode.val())
    		showNode.text(showNode.text().replace(/[\n]/g,"<br>"));
    		show.html(showNode.text());
        	$("#contentMain")[0].scrollTop = pullOffset+"px";
        	getDivLength();
        }
        mScroll.refresh();
//        initScroll ();
        pageIsChange();// 监听页面的变化
    }
    evtHandler.refreshEdit = function(node){
		showNode.val(node.val());
		if(node.val().length>500){
			setPromptForInput("输入字数不能超过500");
		}
    }
    
    
    // 查看详情
    evtHandler.renderSingleItem = function(node){
        var index = parseInt(node.attr("data-index")),
            kpiType = node.attr("kpi-type"),
            item = pageData[kpiType][index],
            dot;
        curListIndex = parseInt(node.attr("list-index"));
        curItemType = kpiType;
        curKpiItem = item;
        switch (kpiType){
            case "kpi":
                item.index = index + 1;
                item.xh = index;
                saveRule = {
                    "doneText" : {maxLen:254, lenErrMsg:"本月完成项内容最多254字，请减少内容字数"},
                };
                dot = doT.template($("#kpi-edit-tpl").html());
                
                break;
            case "ew":
                item.index = index + 1;
                item.xh = index;
                saveRule = {
//                    "doneText" : {required:true,  maxLen:500, emptyMsg : "请填写实际完成项内容",  lenErrMsg:"实际完成项内容最多500字，请减少内容字数"},
//                    "nMontText" : {required:true,  maxLen:500, emptyMsg : "请填写下月行动项内容",  lenErrMsg:"下月行动项内容最多500字，请减少内容字数"},
//                    "sumText" : {required:true,  maxLen:500, emptyMsg : "请填写阶段汇总项内容",  lenErrMsg:"阶段汇总项内容最多500字，请减少内容字数"}
                		"doneText" : {maxLen:500, lenErrMsg:"实际完成项内容最多500字，请减少内容字数"},
                        "nMontText" : {maxLen:500, lenErrMsg:"下月行动项内容最多500字，请减少内容字数"},
                        "sumText" : {maxLen:500, lenErrMsg:"阶段汇总项内容最多500字，请减少内容字数"}
                };
                dot = doT.template($("#ew-edit-tpl").html());
                break;
            case "ewg":
                item.index = pageData.ew.length + index + 1;
                item.xh = index;
                if(item.ewg_status=="CO"){
	                saveRule = {
//	                    "doneText" : {required:true, maxLen : 500, emptyMsg : "请填写实际完成项内容",lenErrMsg : "实际完成项内容最多500字，请减少内容字数"},
//	                    "nMontText" : {required:true, maxLen : 500, emptyMsg : "请填写下月行动项内容",lenErrMsg: "下月行动项内容最多500字，请减少内容字数"},
//	                    "scoreText" : {required:true,minVal : 0,maxVal : 100,valErrMsg : "评分范围为0~100，请输入正确的分数",emptyMsg : "您有工作计划未评分，请评分"},
//	                    "sumText" : {required:true,  maxLen:500, emptyMsg : "请填写阶段汇总项内容",  lenErrMsg:"阶段汇总项内容最多500字，请减少内容字数"}
	                		"scoreText" : {minVal : 0,maxVal : 100,valErrMsg : "评分范围为0~100，请输入正确的分数"},
	                		"doneText" : {maxLen : 500, lenErrMsg : "实际完成项内容最多500字，请减少内容字数"},
		                    "nMontText" : {maxLen : 500, lenErrMsg: "下月行动项内容最多500字，请减少内容字数"},
		                    "sumText" : {maxLen:500,  lenErrMsg:"阶段汇总项内容最多500字，请减少内容字数"}
	                };
                }else{
                	saveRule = {
//	                    "doneText" : {required:true, maxLen : 500, emptyMsg : "请填写实际完成项内容",lenErrMsg : "实际完成项内容最多500字，请减少内容字数"},
//	                    "nMontText" : {required:true,  maxLen : 500, emptyMsg : "请填写下月行动项内容",lenErrMsg : "下月行动项内容最多500字，请减少内容字数"},
//	                    "scoreText" : {required:true,minVal : 0,maxVal : 100,valErrMsg : "评分范围为0~100，请输入正确的分数",emptyMsg : "您有工作计划未评分，请评分"},
// "sumText" : {required:true, maxLen:500, emptyMsg : "请填写阶段汇总项内容",
// lenErrMsg:"阶段汇总项内容最多500字，请减少内容字数"}
                			"scoreText" : {minVal : 0,maxVal : 100,valErrMsg : "评分范围为0~100，请输入正确的分数"},
                			"doneText" : {maxLen : 500, lenErrMsg : "实际完成项内容最多500字，请减少内容字数"},
		                    "nMontText" : {maxLen : 500, lenErrMsg: "下月行动项内容最多500字，请减少内容字数"},
		                    "sumText" : {maxLen:500,  lenErrMsg:"阶段汇总项内容最多500字，请减少内容字数"}
                	};
                }
                // 判断是否评分月
                dot = doT.template($("#ewg-edit-tpl").html());
                break;
            case "ewn":
                item.index = pageData.ew.length +pageData.ewg.length + index + 1;
                item.xh = index;
                saveRule = {
//                    "titleText" : {required:true, maxLen:254, emptyMsg:"请填写新增关键工作计划的标题项内容",lenErrMsg:"标题最多254个字，请减少标题字数。"},
//                    "doneText" : {required:true, maxLen:500, emptyMsg : "请填写实际完成项内容",  lenErrMsg:"实际完成项内容最多500字，请减少内容字数"},
//                    "nMontText" : {required:true,  maxLen:500, emptyMsg : "请填写下月行动项内容",  lenErrMsg:"下月行动项内容最多500字，请减少内容字数"},
//                    "sumText" : {required:true,  maxLen:500, emptyMsg : "请填写阶段汇总项内容",  lenErrMsg:"阶段汇总项内容最多500字，请减少内容字数"}
                		"titleText" : {maxLen:254,lenErrMsg:"标题最多254个字，请减少标题字数。"},
                		"doneText" : {maxLen : 500, lenErrMsg : "实际完成项内容最多500字，请减少内容字数"},
	                    "nMontText" : {maxLen : 500, lenErrMsg: "下月行动项内容最多500字，请减少内容字数"},
	                    "sumText" : {maxLen:500,  lenErrMsg:"阶段汇总项内容最多500字，请减少内容字数"}
                };
                dot = doT.template($("#ewn-new-tpl").html());
                break;
        }
        $("#content").html(dot(item));
        if(kpiType=="ewg"){
        	if(item.ewg_status=="CO" && item.ewg_status_app=="0"){
                $("#doneText").attr("et","");
                $("#nMontText").attr("et","");
                $("#sumText").attr("et","");
                	
                if(item.ewg_status="CO"){
                	$("#select_a").html("已经完成"+
                		"<div param-name='EP_TRK_STATUS' style='display:none;'>CO</div>");
                }	else{
                	$("#select_a").html("正在进行"+
        				"<div param-name='EP_TRK_STATUS' style='display:none;'>IP</div>");
                }
            }
            if(item.iscyc=="0"){
                $("#ldpf").hide();
                saveRule = {
// "doneText" : {required:true, maxLen : 500, emptyMsg : "请填写实际完成项内容",lenErrMsg
// : "实际完成项内容最多500字，请减少内容字数"},
// "nMontText" : {required:true, maxLen : 500, emptyMsg : "请填写下月行动项内容",lenErrMsg
// : "下月行动项内容最多500字，请减少内容字数"},
// "scoreText" : {},
// "sumText" : {required:true, maxLen:500, emptyMsg : "请填写阶段汇总项内容",
// lenErrMsg:"阶段汇总项内容最多500字，请减少内容字数"}
  
                };
            }else{
            	if(item.ewg_status == "CO" && item.ewg_status_app == "0" && item.ewg_status_app1!="2"){
            		$("#ldpf").hide();
            		saveRule = {
// "doneText" : {required:true, maxLen : 500, emptyMsg : "请填写实际完成项内容",lenErrMsg
// : "实际完成项内容最多500字，请减少内容字数"},
// "nMontText" : {required:true, maxLen : 500, emptyMsg : "请填写下月行动项内容",lenErrMsg
// : "下月行动项内容最多500字，请减少内容字数"},
// "scoreText" : {},
// "sumText" : {required:true, maxLen:500, emptyMsg : "请填写阶段汇总项内容",
// lenErrMsg:"阶段汇总项内容最多500字，请减少内容字数"}
                	};
            	}
            }
        }
        getDivLength();//页面实际完成DIV初始化高度！
        closeLeftSide();
        mScroll.refresh();
        // myIscroll.refresh();
    }

    // 添加工作计划
    evtHandler.addKeywork = function(){
        var create_item_tpl = $("#create-item-tpl").html();
        pageData.ewn.push({
            "ewn_descr": "新增关键工作计划",
            "ewn_nco": "",
            "ewn_rea": "",
            "ewn_section_id": "",
            "ewn_status": "IP",
            "ewn_sum": "",
            "ewn_up_nco": "",
            "isCreate" : true
        });

// $("#createKeywork").before(create_item_tpl.replace("{#dataIndex#}",
// maxEwnListIndex++).replace("{#listIndex#}",
// maxListIndex++).replace("{#kwListIndex#}",
// pageData.ew.length+pageData.ewg.length+maxEwnListIndex));
		$("#createKeywork").parent().before(create_item_tpl.replace("{#dataIndex#}", maxEwnListIndex++).replace("{#listIndex#}", maxListIndex++).replace("{#kwListIndex#}", pageData.ew.length+pageData.ewg.length+maxEwnListIndex));
        $('div[list-index="' + (maxListIndex-1) + '"]').trigger("tap");
        closeLeftSide();
        inputTitle();
    }

    // 保存
    evtHandler.save = function(){
    	Ifsave = false;
    	changeFlag = false;
    	Textyz();
    	ClearOkPf();// 去除点击按钮效果
    	$("#loading").show();
        var submitParams={}, url, paramNodes = $("#content").find("[param-name]");
        paramNodes.forEach(function(node){
            params[node.getAttribute("param-name")] = node.value || node.innerText;
        });
        
        // 是否新增关键计划 01 新增 00 修改
        var isnew = "00";
        
        // 保存 汇报状态为 未提交 USUB
        // pageData.report.PAIC_MON_STATUS = "USUB";
        // pageData.report.pAIC_MON_STATUS = "USUB";
        // 主表数据
        params.EP_APPRAISAL_ID = pageData.report.ep_appraisal_id;
        params.MONTH_EP = pageData.report.eVA_MONTH_EP;
        params.YEAR_EP = pageData.report.yEAR_EP;

        var reportObj = pageData.report;

        // 主表的状态 KPI 的 完成情况
        // ewg 增加了PAIC_SELF_RATING 这个才是自评分，我接口写错了
        var report_src = "{'EMPLID':'" + reportObj.eMPLID + "'," +
            "'EP_APPRAISAL_ID':'" + reportObj.ep_appraisal_id + "'," +
            "'EP_MANAGER1_ID':'" + reportObj.eP_MANAGER1_ID + "'," +
            "'EP_MANAGER2_ID':'" + reportObj.eP_MANAGER2_ID + "'," +
            "'EP_MANAGER3_ID':'" + reportObj.eP_MANAGER3_ID + "'," +
            "'EP_TEMPLATE_ID':'" + reportObj.eP_TEMPLATE_ID + "'," +
            "'EVA_GROUP_ID':'" + reportObj.eVA_GROUP_ID + "'," +
            "'GRADED_CYC':'" + reportObj.gRADED_CYC + "'," +
            "'MONTH_EP':'" + reportObj.eVA_MONTH_EP + "'," +
            "'PAIC_MON_STATUS':'"+pageData.report.pAIC_MON_STATUS+"'," +
            "'YEAR_EP':'" + reportObj.yEAR_EP + "'}";

		var xh = params.xh;
        switch (curItemType) {
            case "kpi":
            	// 更新数据
            	
            	pageData.kpi[xh].paic_accmp_sta = params.PAIC_ACCMP_STA;
            	// 将原始数据进行转码传到后台
            	params.PAIC_ACCMP_STA=params.PAIC_ACCMP_STA.replace(/<br>/g,"\n");
            	
            	params.PAIC_ACCMP_STA=params.PAIC_ACCMP_STA.replace(/\'/g,"’");
            	params.PAIC_ACCMP_STA=params.PAIC_ACCMP_STA.replace(/\\/g,"/");
            	
                url = mpsurl+"/mobile/report/addReportKPI.do";
                var kpi_src ="[{'CONTENT_DESCR':'" + params.CONTENT_DESCR + "'," +
                    "'EP_APPRAISAL_ID':'" + params.EP_APPRAISAL_ID + "'," +
                    "'MONTH_EP':'" + params.MONTH_EP + "'," +
                    "'PAIC_ACCMP_STA':'" + params.PAIC_ACCMP_STA + "'," +
                    "'SECTION_ID':'" + params.SECTION_ID + "'," +
                    "'YEAR_EP':'" + params.YEAR_EP + "'}]";
                submitParams = {
                    report : report_src,
                    kpi_list : kpi_src
                }
                break;
            case "ew":
            	
            	// 赋值
            	pageData.ew[xh].ew_rea=params.PAIC_EP_RESERVED1;
            	pageData.ew[xh].ew_nco=params.PAIC_EP_RESERVED2;
            	pageData.ew[xh].ew_sum=params.PAIC_EP_RESERVED3;
            	pageData.ew[xh].ew_status=params.EP_TRK_STATUS;
            	// 原始数据传给后台！
            	params.PAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1.replace(/<br>/g,"\n");
            	params.PAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2.replace(/<br>/g,"\n");
            	params.PAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3.replace(/<br>/g,"\n");
            	
            	
            	
            	
            	
            	params.PAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1.replace(/\\/g,"/");
            	params.PAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2.replace(/\\/g,"/");
            	params.PAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3.replace(/\\/g,"/");
            	
            	
            	
                url = mpsurl+"/mobile/report/addReportEW.do";
                var strew = "[{'CONTENT_DESCR':'" + params.CONTENT_DESCR + "'," +
                    "'EP_APPRAISAL_ID':'" + params.EP_APPRAISAL_ID + "'," +
                    "'EP_TRK_STATUS':'" + params.EP_TRK_STATUS + "'," +
                    "'MONTH_EP':'" + params.MONTH_EP + "'," +
                    "'EP_TRK_STATUS':'" + params.EP_TRK_STATUS + "'," +
                    "'PAIC_EP_RESERVED1':'" + params.PAIC_EP_RESERVED1 + "'," +
                    "'PAIC_EP_RESERVED2':'" + params.PAIC_EP_RESERVED2 + "'," +
                    "'PAIC_EP_RESERVED3':'" + params.PAIC_EP_RESERVED3 + "'," +
                    "'PAIC_EXPECTATION':'" + params.PAIC_EXPECTATION + "'," +
                    "'SECTION_ID':'" + params.SECTION_ID + "'," +
                    "'YEAR_EP':'" + params.YEAR_EP + "'}]";
                submitParams = {
                    report : report_src,
                    ew_list : strew
                }
                break;
            case "ewg":
            	// 更新数据
            	// 赋值
            	pageData.ewg[xh].ewg_rea=params.PAIC_EP_RESERVED1;
            	pageData.ewg[xh].ewg_nco=params.PAIC_EP_RESERVED2;
            	pageData.ewg[xh].ewg_sum=params.PAIC_EP_RESERVED3;
            	pageData.ewg[xh].ewg_status=params.EP_TRK_STATUS;
            	pageData.ewg[xh].ewg_self_rating=params.PAIC_SELF_RATING;
            	
            	// 原始数据传给后台！
            	params.PAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1.replace(/<br>/g,"\n");
            	params.PAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2.replace(/<br>/g,"\n");
            	params.PAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3.replace(/<br>/g,"\n");
				params.PAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1.replace(/\\/g,"/");
            	params.PAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2.replace(/\\/g,"/");
            	params.PAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3.replace(/\\/g,"/");
            	
                url = mpsurl+"/mobile/report/addReportEWG.do";
                var strewg = "[{'CONTENT_DESCR':'" + params.CONTENT_DESCR + "'," +
                    "'EP_APPRAISAL_ID':'" + params.EP_APPRAISAL_ID + "'," +
                    "'EP_TRK_STATUS':'" + params.EP_TRK_STATUS + "'," +
                    "'EVA_WEIGHT':'" + params.EVA_WEIGHT + "'," +
                    "'PAIC_SELF_RATING':'" + params.PAIC_SELF_RATING + "'," +
                    "'MONTH_EP':'" + params.MONTH_EP + "'," +
                    "'PAIC_EP_RESERVED1':'" + params.PAIC_EP_RESERVED1 + "'," +
                    "'PAIC_EP_RESERVED2':'" + params.PAIC_EP_RESERVED2 + "'," +
                    "'PAIC_EP_RESERVED3':'" + params.PAIC_EP_RESERVED3 + "'," +
                    "'PAIC_EXPECTATION':'" + params.PAIC_EXPECTATION + "'," +
                    "'SECTION_ID':'" + params.SECTION_ID + "'," +
                    "'YEAR_EP':'" + params.YEAR_EP + "'}]";
                submitParams = {
                    report : report_src,
                    ewg_list : strewg
                }
                break;
            case "ewn":
            	// 更新数据
            	
            	// 赋值
            	pageData.ewn[xh].ewn_rea=params.PAIC_EP_RESERVED1;
            	pageData.ewn[xh].ewn_nco=params.PAIC_EP_RESERVED2;
            	pageData.ewn[xh].ewn_sum=params.PAIC_EP_RESERVED3;
            	pageData.ewn[xh].ewn_status=params.EP_TRK_STATUS;
            	
            	// 原始数据传给后台！
            	params.PAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1.replace(/<br>/g,"\n");
            	params.PAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2.replace(/<br>/g,"\n");
            	params.PAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3.replace(/<br>/g,"\n");
				
            	isnew = params.FLAG7;
            	params.PAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1.replace(/\\/g,"/");
            	params.PAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2.replace(/\\/g,"/");
            	params.PAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3.replace(/\\/g,"/");
            	params.CONTENT_DESCR=params.CONTENT_DESCR.replace(/\'/g,"’");
                url = mpsurl+"/mobile/report/addReportEWN.do";
                var strewn = "[{'CONTENT_DESCR':'" + params.CONTENT_DESCR + "'," +
                    "'EP_APPRAISAL_ID':'" + params.EP_APPRAISAL_ID + "'," +
                    "'EP_TRK_STATUS':'" + params.EP_TRK_STATUS + "'," +
                    "'FLAG7':'" + params.FLAG7 + "'," +
                    "'MONTH_EP':'" + params.MONTH_EP + "'," +
                    "'PAIC_EP_RESERVED1':'" + params.PAIC_EP_RESERVED1 + "'," +
                    "'PAIC_EP_RESERVED2':'" + params.PAIC_EP_RESERVED2 + "'," +
                    "'PAIC_EP_RESERVED3':'" + params.PAIC_EP_RESERVED3 + "'," +
                    "'PAIC_EXPECTATION':'" + params.PAIC_EXPECTATION + "'," +
                    "'SECTION_ID':'" + params.SECTION_ID + "'," +
                    "'YEAR_EP':'" + params.YEAR_EP + "'}]";
                submitParams = {
                    report : report_src,
                    ewn_list : strewn
                }
                break;
        }
        if(!validateForm(saveRule)){
        	GetOkPf();// 得到点击效果！
            $("#loading").hide();
            return;
        }
        $.ajax({
            type : "post",
            url : url,
            dataType : "json",
            data :submitParams,
            success : function(json) {
        		$("#loading").hide();
        		GetOkPf();// 得到点击效果
                if (json.resultCode == "500600") {
                    autoClosePrompt(json.HR_SSTEXT_TEXT);
                    // 新增关键计划，跳转页面
                    if(isnew=="01"){
                    	setTimeout(function(){
                    		// location.href="/mobile/kpi/kpi-todo.html?report_date="+report_date;
                    		var param = "report_date="+ report_date;
							gotoLocation("/mobile/kpi/kpi-todo.html",param);
                    	},2000);
                    }else{
                    	GetOkPf();// 得到点击效果！
                    }
                } else {
                	GetOkPf();// 得到点击效果！
                	$("#loading").hide();
                	if(json.resultCode=="500702" || json.resultCode=="500802" || json.resultCode=="500803"){
                		var tourl = "/mobile/kpi/kpi-todo.html?report_date="+report_date;
                		checkLogin(json.resultCode,tourl,json.resultMessage);
                	}else{
                   		autoClosePrompt(json.resultMessage);
                    }
                }
            },
            error: function (xhr, textStatus, errorThrown) {
            	GetOkPf();// 得到点击效果！
            	$("#loading").hide();
                autoClosePrompt("网络连接异常");
			}
        });
        
    }

    
    // 切换工作计划的状态
    evtHandler.changeStatus = function(node){
    	statuses = node.val();
    	if(statuses=="CO"){
    		$("#nMontText").html("");
    	}
        $("#nMonthDiv").toggle();
        $("#sumDiv").toggle();
    }

    
    evtHandler.toScore = function(){
    	Textyz();
    	statuses = $("select").val();
    	if(!validateForm(saveRule)){
            return;
        }
    	evtHandler.saveNoyz("N");
		// location.href = "kpi-toScore.html?report_date="+report_date;
		var param = "report_date="+ report_date;
		gotoLocation("/mobile/kpi/kpi-toScore.html",param);
    }

    
    evtHandler.show = function(){// 日历显示效果
        $('#bdate').scroller('show');
        $(".dwo").css("background-color","#000");
	    $(".dwo").css("opacity",".5");
	    $(".dwo").css("z-index","1000");
    }
    
    $(document).on("tap", function(){
	    $(".dw dwbg").on("tap",function(){
	    	return;
	    })
	    $(".dwo").on("tap",function(){
	    	$("#promptBox").remove("slow");	
	    })
	    $(".dwbw dwb-c").on("tap",function(){
	    	$("#promptBox").remove("slow");	
	    })
	    $(".dwbw dwb-s").on("tap",function(){
	    	$("#promptBox").remove("slow");	
	    })
	});
    evtHandler.change = function(){
        $("#month").text($("#bdate").val().substr(5,2));
        report_date = $("#bdate").val();
        loadPageData($("#bdate").val());
    }
  // 点击返回判断不是$("#status").val()=="CO"&& $("#app").val()=="0"进行保存
    evtHandler.back = function(){
    	/*
    	//安卓关闭键盘
		var ua = navigator.userAgent;
		if(ua.indexOf("iPhone")>=0){
		}else{
			window.pa_app.closeKeyboard();
		}
		*/
    	if($("#status").val()=="CO" && $("#app").val()=="0"){
    		return ;
		}else{	
			Textyz();
			evtHandler.saveNoyz("N");
		}
		setTimeout(function(){
			gotoLocation("/mobile/index.html","");
		},200);
	  }
    // 删除关键工作计划
    evtHandler.delEwn = function(node){
    	$("#loading").show();
    	ClearOkPf();
    	var paramNodes = $("#content").find("[param-name]");
        paramNodes.forEach(function(node){
            params[node.getAttribute("param-name")] = node.value || node.innerText;
        });
    	$("#titile").html(params.CONTENT_DESCR+"吗？");
    	var reportObj = pageData.report;
        var report_src = "{'EMPLID':'" + reportObj.eMPLID + "'," +
            "'EP_APPRAISAL_ID':'" + reportObj.ep_appraisal_id + "'," +
            "'EP_MANAGER1_ID':'" + reportObj.eP_MANAGER1_ID + "'," +
            "'EP_MANAGER2_ID':'" + reportObj.eP_MANAGER2_ID + "'," +
            "'EP_MANAGER3_ID':'" + reportObj.eP_MANAGER3_ID + "'," +
            "'EP_TEMPLATE_ID':'" + reportObj.eP_TEMPLATE_ID + "'," +
            "'EVA_GROUP_ID':'" + reportObj.eVA_GROUP_ID + "'," +
            "'GRADED_CYC':'" + reportObj.gRADED_CYC + "'," +
            "'MONTH_EP':'" + reportObj.eVA_MONTH_EP + "'," +
            "'PAIC_MON_STATUS':'"+reportObj.pAIC_MON_STATUS+"'," +
            "'YEAR_EP':'" + reportObj.yEAR_EP + "'}";
        $("#report").attr("value",report_src);
        params.EP_APPRAISAL_ID = pageData.report.ep_appraisal_id;
        params.MONTH_EP = pageData.report.eVA_MONTH_EP;
        params.YEAR_EP = pageData.report.yEAR_EP;
            
        var strewn = "[{'CONTENT_DESCR':'" + params.CONTENT_DESCR + "'," +
                    "'EP_APPRAISAL_ID':'" + params.EP_APPRAISAL_ID + "'," +
                    "'EP_TRK_STATUS':'" + params.EP_TRK_STATUS + "'," +
                    "'FLAG7':'02'," +
                    "'MONTH_EP':'" + params.MONTH_EP + "'," +
                    "'PAIC_EP_RESERVED1':'" + params.PAIC_EP_RESERVED1 + "'," +
                    "'PAIC_EP_RESERVED2':'" + params.PAIC_EP_RESERVED2 + "'," +
                    "'PAIC_EP_RESERVED3':'" + params.PAIC_EP_RESERVED3 + "'," +
                    "'PAIC_EXPECTATION':'" + params.PAIC_EXPECTATION + "'," +
                    "'SECTION_ID':'" + params.SECTION_ID + "'," +
                    "'YEAR_EP':'" + params.YEAR_EP + "'}]";
        $("#ewnlist").attr("value",strewn);
    	$("#GlobalMask").show();
    	
    }
    $("#ewnCancel").on("tap",function(){
    	$("#GlobalMask").hide();
    	$("#loading").hide();
    	GetOkPf();
    });
    $("#ewnDelete").on("tap",function(){
    	var report_src = $("#report").val();
    	var strewn = $("#ewnlist").val();
    	$.ajax({
            type : "post",
            url : mpsurl+"/mobile/report/addReportEWN.do",
            dataType : "json",
            data : {
    			report : report_src,
                ewn_list : strewn
            },
            success : function(json) {
                if (json.resultCode == "500600") {
                    autoClosePrompt(json.HR_SSTEXT_TEXT);
                    setTimeout(function(){
                    	// location.href="/mobile/kpi/kpi-todo.html?report_date="+report_date;
                    	var param = "report_date="+ report_date;
						gotoLocation("/mobile/kpi/kpi-todo.html",param);
                    },3100);
                    $("#loading").hide();
                	GetOkPf();
                } else {
                	$("#loading").hide();
                	GetOkPf();
                	if(json.resultCode=="500702" || json.resultCode=="500802" || json.resultCode=="500803"){
                		var tourl = "/mobile/kpi/kpi-todo.html?report_date="+report_date;
                		checkLogin(json.resultCode,tourl,json.resultMessage);
                	}else{
                   		autoClosePrompt(json.resultMessage);
                    }
                }
            }
        });
    	
    	$("#GlobalMask").hide();
    });
   
}

/**
 * 检测月度汇报状态
 */
function checkStatus (status,report_date) {
	// {"USUB":"未提交","SUBM":"待确认","APP":"已确认","BAC":"驳回","NON":"未制定"};
    if(status=="SUBM" || status=="APP"){
    	// location.href="/mobile/myreport/wdydbg-chakan.html?report_date="+report_date;
    	var param = "report_date="+ report_date;
		gotoLocation("/mobile/myreport/wdydbg-chakan.html",param);
    	return ;
    }
}

/**
 * 获取当月KPI数据
 */
function loadPageData (report_date) {
	ClearOkPf();
	$("#month").text(report_date.substr(5,2));
	$("#loading").show();
	$("#contentMain").hide();
    $.ajax({
     	url : mpsurl+"/mobile/report/queryMyReport.do",
// url:"kpi-todo.do",
        dataType : "json",
        data : {
// method:"kpi-todo",
            report_date : report_date
        },
        type : "post",
        success : function(json) {
        	$("#loading").hide();
        	$("#contentMain").show();
            if (json.resultCode == "500600") {
                pageData = json.value;
                // 检测月度汇报状态，根据状态判断 编辑页面 和 查看页面
                checkStatus(pageData.report.pAIC_MON_STATUS,report_date);
                maxListIndex = pageData.kpi.length + pageData.ew.length
                    + pageData.ewg.length + pageData.ewn.length;
                maxEwnListIndex = pageData.ewn.length;
                renderPage();
                GetOkPf();
            } else {
            	ClearOkPf();
            	if(json.resultCode=="500702" || json.resultCode=="500802" || json.resultCode=="500803"){
                		var tourl = "/mobile/kpi/kpi-todo.html?report_date="+report_date;
                		checkLogin(json.resultCode,tourl,json.resultMessage);
                }else{
                   		autoClosePrompt(json.resultMessage || "网络连接异常");
                }
            }
        },
        error: function (xhr, textStatus, errorThrown) {
        	$("#loading").hide();
			$("#errorMask").find("p").text("网络连接异常");
			$("#errorMask").show(); 
			setTimeout(function(){$("#errorMask").hide();},5000);
			ClearOkPf();
		}
    });
}

/**
 * 渲染KPI页面数据
 */
function renderPage () {
    var dot = doT.template($("#left-side-tpl").html());
    var staArr = {"USUB":"未提交","SUBM":"待确认","APP":"已确认","BAC":"已驳回","NON":"未制定"};
    var reportStatus = pageData.report.pAIC_MON_STATUS;
	for(var perSta in staArr){
		if(perSta == reportStatus){
			reportStatus = staArr[perSta];
		}
	}
    $("#statusNode").text(reportStatus);
    $("#leftSideContent").html(dot(pageData));
    if(pageData.kpi.length>0){
   		$("#kpiList").find("div:first-child").trigger("tap"); 
    }else{
    	$("#keyworkList").find("div:first-child").trigger("tap");
    }
}

function openLeftSide (){
    $("#wrap").addClass("open-side");
    $("#leftSide").show();
 	countPageHeight();
    myIscroll.refresh();
}
function closeLeftSide (){
    $("#wrap").removeClass("open-side");
}


/**
 * 将一位日期显示成两位
 */
function formatDate(num){
    num = ""+num;
    return num.length <=1 ? "0"+num : num;
}
function autoClosePrompt(message, id){    
    var promptTemple = "<div class='check-prompt' id='CheckPrompt'>" +
                          "<div class='check-prompt-bg'></div>" +
                          "<div class='check-prompt-txt'>" + message + "</div>" +
                       "</div>";
    $("body").append(promptTemple);
    setTimeout(function(){
        $("#CheckPrompt").remove("slow");
    }, 1500)
    if(id != null){
    	id="#"+id;
    	var txt = $(id).text();
		var dv = $(id).parent()
		dv.parents("li").addClass("edit-enable");
		var nxt = dv.next().find("textarea");
		if(txt==null||txt==""){
			nxt.focus();	
		}else{
			$(nxt).val(txt);
			nxt.focus();
		}
		mScroll.refresh();
    }
}
// ajax返回错误信息，弹出层
/*
 * function errorMask(message, id){ autoClosePrompt(message, id); }
 */


function ClearOkPf(){
	$("#Ok").hide();
	$("#NoOk").show();
	$("#pf").hide();
	$("#Nopf").show();
}

function GetOkPf(){
	$("#Ok").show();
	$("#NoOk").hide();
	$("#pf").show();
	$("#Nopf").hide();
}


function Textyz(){// 文本验证！！
	if($("#benyue").val()!=undefined){
		if($("#benyue").val()!=""){
    		$("#benyue").val($("#benyue").val().replace(/[\r\n]/g,"<br>"));
        	$("#doneText").html($("#benyue").val());
        	$("#doneText").parent().parent().removeClass("edit-enable");	
        	$("#contentMain")[0].scrollTop = pullOffset+"px";
        }
	}
	if($("#xiayue").val()!=undefined){
		if($("#xiayue").val()!=""){
    		$("#xiayue").val($("#xiayue").val().replace(/[\r\n]/g,"<br>"));
        	$("#nMontText").html($("#xiayue").val());
        	$("#nMontText").parent().parent().removeClass("edit-enable");
        	$("#contentMain")[0].scrollTop = pullOffset+"px";
        }
	}
	if($("#jieduan").val()!=undefined){
		if($("#xiayue").val()!=""){
    		$("#jieduan").val($("#jieduan").val().replace(/[\r\n]/g,"<br>"));
        	$("#sumText").html($("#jieduan").val());
        	$("#sumText").parent().parent().removeClass("edit-enable");
        	$("#contentMain")[0].scrollTop = pullOffset+"px";
        }
	}
	getDivLength();
}
evtHandler.saveNoyz = function(saveFlag){
	
    var submitParams={}, url, paramNodes = $("#content").find("[param-name]");
    paramNodes.forEach(function(node){
        params[node.getAttribute("param-name")] = node.value || node.innerText;
    });
    
    // 是否新增关键计划 01 新增 00 修改
    var isnew = "00";
    
    // 保存 汇报状态为 未提交 USUB
    // pageData.report.PAIC_MON_STATUS = "USUB";
    // pageData.report.pAIC_MON_STATUS = "USUB";
    // 主表数据
    params.EP_APPRAISAL_ID = pageData.report.ep_appraisal_id;
    params.MONTH_EP = pageData.report.eVA_MONTH_EP;
    params.YEAR_EP = pageData.report.yEAR_EP;

    var reportObj = pageData.report;

    // 主表的状态 KPI 的 完成情况
    // ewg 增加了PAIC_SELF_RATING 这个才是自评分，我接口写错了
    
    var report_src = "{'EMPLID':'" + reportObj.eMPLID + "'," +
        "'EP_APPRAISAL_ID':'" + reportObj.ep_appraisal_id + "'," +
        "'EP_MANAGER1_ID':'" + reportObj.eP_MANAGER1_ID + "'," +
        "'EP_MANAGER2_ID':'" + reportObj.eP_MANAGER2_ID + "'," +
        "'EP_MANAGER3_ID':'" + reportObj.eP_MANAGER3_ID + "'," +
        "'EP_TEMPLATE_ID':'" + reportObj.eP_TEMPLATE_ID + "'," +
        "'EVA_GROUP_ID':'" + reportObj.eVA_GROUP_ID + "'," +
        "'GRADED_CYC':'" + reportObj.gRADED_CYC + "'," +
        "'MONTH_EP':'" + reportObj.eVA_MONTH_EP + "'," +
        "'PAIC_MON_STATUS':'"+pageData.report.pAIC_MON_STATUS+"'," +
        "'YEAR_EP':'" + reportObj.yEAR_EP + "'}";
	
	var xh = params.xh;
    switch (curItemType) {
        case "kpi":
        	// 更新数据
        	var newPAIC_ACCMP_STA=params.PAIC_ACCMP_STA;// 得到原始数据！
        	if(saveFlag == "Y"){
        		newPAIC_ACCMP_STA = $("#benyue").val();
        		newPAIC_ACCMP_STA=newPAIC_ACCMP_STA.replace(/<br>/g,"\n");
        	}
        	// 给页面赋值
        	
        	pageData.kpi[xh].paic_accmp_sta = params.PAIC_ACCMP_STA;
        	// 将原始数据进行转码传到后台
        	params.PAIC_ACCMP_STA=newPAIC_ACCMP_STA
        	
        	params.PAIC_ACCMP_STA=params.PAIC_ACCMP_STA.replace(/\'/g,"’");
        	params.PAIC_ACCMP_STA=params.PAIC_ACCMP_STA.replace(/\\/g,"/");
            url = mpsurl+"/mobile/report/addReportKPI.do";
            var kpi_src ="[{'CONTENT_DESCR':'" + params.CONTENT_DESCR + "'," +
                "'EP_APPRAISAL_ID':'" + params.EP_APPRAISAL_ID + "'," +
                "'MONTH_EP':'" + params.MONTH_EP + "'," +
                "'PAIC_ACCMP_STA':'" + params.PAIC_ACCMP_STA + "'," +
                "'SECTION_ID':'" + params.SECTION_ID + "'," +
                "'YEAR_EP':'" + params.YEAR_EP + "'}]";
            submitParams = {
                report : report_src,
                kpi_list : kpi_src
            }
            break;
        case "ew":
        	// 更新数据
        	var newPAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1;
        	var newPAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2;
        	var newPAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3;
        	if(saveFlag == "Y"){
        		if(params.PAIC_EP_RESERVED1!=null&&params.PAIC_EP_RESERVED1!=""){
        			newPAIC_EP_RESERVED1 = params.PAIC_EP_RESERVED1;
        		}else{
        			newPAIC_EP_RESERVED1 = $("#benyue").val();
        		}
        		if(params.PAIC_EP_RESERVED2!=null&&params.PAIC_EP_RESERVED2!=""){
        			newPAIC_EP_RESERVED2 = params.PAIC_EP_RESERVED2;
        		}else{
        			newPAIC_EP_RESERVED2 = $("#xiayue").val();
        		}
        		if(params.PAIC_EP_RESERVED3!=null&&params.PAIC_EP_RESERVED3!=""){
        			newPAIC_EP_RESERVED3 = params.PAIC_EP_RESERVED3;
        		}else{
        			newPAIC_EP_RESERVED3 = $("#jieduan").val();
        		}
        		newPAIC_EP_RESERVED1=newPAIC_EP_RESERVED1.replace(/<br>/g,"\n");
        		newPAIC_EP_RESERVED2=newPAIC_EP_RESERVED2.replace(/<br>/g,"\n");
        		newPAIC_EP_RESERVED3=newPAIC_EP_RESERVED3.replace(/<br>/g,"\n");
        	}
        	
        	// 赋值
        	pageData.ew[xh].ew_rea=params.PAIC_EP_RESERVED1;
        	pageData.ew[xh].ew_nco=params.PAIC_EP_RESERVED2;
        	pageData.ew[xh].ew_sum=params.PAIC_EP_RESERVED3;
        	pageData.ew[xh].ew_status=params.EP_TRK_STATUS;
        	
        	
        	
        	// 原始数据传给后台！
				params.PAIC_EP_RESERVED1=newPAIC_EP_RESERVED1;
				params.PAIC_EP_RESERVED2=newPAIC_EP_RESERVED2;
				params.PAIC_EP_RESERVED3=newPAIC_EP_RESERVED3;
	        	
				params.PAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3.replace(/\'/g,"’");
            	
            	params.PAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1.replace(/\\/g,"/");
            	params.PAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2.replace(/\\/g,"/");
            	params.PAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3.replace(/\\/g,"/");
            url = mpsurl+"/mobile/report/addReportEW.do";
            var strew = "[{'CONTENT_DESCR':'" + params.CONTENT_DESCR + "'," +
                "'EP_APPRAISAL_ID':'" + params.EP_APPRAISAL_ID + "'," +
                "'EP_TRK_STATUS':'" + params.EP_TRK_STATUS + "'," +
                "'MONTH_EP':'" + params.MONTH_EP + "'," +
                "'EP_TRK_STATUS':'" + params.EP_TRK_STATUS + "'," +
                "'PAIC_EP_RESERVED1':'" + params.PAIC_EP_RESERVED1 + "'," +
                "'PAIC_EP_RESERVED2':'" + params.PAIC_EP_RESERVED2 + "'," +
                "'PAIC_EP_RESERVED3':'" + params.PAIC_EP_RESERVED3 + "'," +
                "'PAIC_EXPECTATION':'" + params.PAIC_EXPECTATION + "'," +
                "'SECTION_ID':'" + params.SECTION_ID + "'," +
                "'YEAR_EP':'" + params.YEAR_EP + "'}]";
            submitParams = {
                report : report_src,
                ew_list : strew
            }
            break;
        case "ewg":
        	// 更新数据
        	var newPAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1;
        	var newPAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2;
        	var newPAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3;
        	if(saveFlag == "Y"){
        		if(params.PAIC_EP_RESERVED1!=null&&params.PAIC_EP_RESERVED1!=""){
        			newPAIC_EP_RESERVED1 = params.PAIC_EP_RESERVED1;
        		}else{
        			newPAIC_EP_RESERVED1 = $("#benyue").val();
        		}
        		if(params.PAIC_EP_RESERVED2!=null&&params.PAIC_EP_RESERVED2!=""){
        			newPAIC_EP_RESERVED2 = params.PAIC_EP_RESERVED2;
        		}else{
        			newPAIC_EP_RESERVED2 = $("#xiayue").val();
        		}
        		if(params.PAIC_EP_RESERVED3!=null&&params.PAIC_EP_RESERVED3!=""){
        			newPAIC_EP_RESERVED3 = params.PAIC_EP_RESERVED3;
        		}else{
        			newPAIC_EP_RESERVED3 = $("#jieduan").val();
        		}
        		newPAIC_EP_RESERVED1=newPAIC_EP_RESERVED1.replace(/<br>/g,"\n");
        		newPAIC_EP_RESERVED2=newPAIC_EP_RESERVED2.replace(/<br>/g,"\n");
        		newPAIC_EP_RESERVED3=newPAIC_EP_RESERVED3.replace(/<br>/g,"\n");
        	}
        	
        	// 转码
        	// &nbsp
        	
        	// 赋值
        	pageData.ewg[xh].ewg_rea=params.PAIC_EP_RESERVED1;
        	pageData.ewg[xh].ewg_nco=params.PAIC_EP_RESERVED2;
        	pageData.ewg[xh].ewg_sum=params.PAIC_EP_RESERVED3;
        	pageData.ewg[xh].ewg_status=params.EP_TRK_STATUS;
        	pageData.ewg[xh].ewg_self_rating=params.PAIC_SELF_RATING;
        	
        	
        	// 将原始数据进行转码传到后台
        	
        	// 原始数据传给后台！
        	
			params.PAIC_EP_RESERVED1=newPAIC_EP_RESERVED1;
			params.PAIC_EP_RESERVED2=newPAIC_EP_RESERVED2;
			params.PAIC_EP_RESERVED3=newPAIC_EP_RESERVED3;
			
				params.PAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1.replace(/\\/g,"/");
            	params.PAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2.replace(/\\/g,"/");
            	params.PAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3.replace(/\\/g,"/");
            	
            url = mpsurl+"/mobile/report/addReportEWG.do";
            var strewg = "[{'CONTENT_DESCR':'" + params.CONTENT_DESCR + "'," +
                "'EP_APPRAISAL_ID':'" + params.EP_APPRAISAL_ID + "'," +
                "'EP_TRK_STATUS':'" + params.EP_TRK_STATUS + "'," +
                "'EVA_WEIGHT':'" + params.EVA_WEIGHT + "'," +
                "'PAIC_SELF_RATING':'" + params.PAIC_SELF_RATING + "'," +
                "'MONTH_EP':'" + params.MONTH_EP + "'," +
                "'PAIC_EP_RESERVED1':'" + params.PAIC_EP_RESERVED1 + "'," +
                "'PAIC_EP_RESERVED2':'" + params.PAIC_EP_RESERVED2 + "'," +
                "'PAIC_EP_RESERVED3':'" + params.PAIC_EP_RESERVED3 + "'," +
                "'PAIC_EXPECTATION':'" + params.PAIC_EXPECTATION + "'," +
                "'SECTION_ID':'" + params.SECTION_ID + "'," +
                "'YEAR_EP':'" + params.YEAR_EP + "'}]";
            submitParams = {
                report : report_src,
                ewg_list : strewg
            }
            break;
        case "ewn":
        	// 更新数据
        	var newPAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1;
        	var newPAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2;
        	var newPAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3;
        	if(saveFlag == "Y"){
        		if(params.PAIC_EP_RESERVED1!=null&&params.PAIC_EP_RESERVED1!=""){
        			newPAIC_EP_RESERVED1 = params.PAIC_EP_RESERVED1;
        		}else{
        			newPAIC_EP_RESERVED1 = $("#benyue").val();
        		}
        		if(params.PAIC_EP_RESERVED2!=null&&params.PAIC_EP_RESERVED2!=""){
        			newPAIC_EP_RESERVED2 = params.PAIC_EP_RESERVED2;
        		}else{
        			newPAIC_EP_RESERVED2 = $("#xiayue").val();
        		}
        		if(params.PAIC_EP_RESERVED3!=null&&params.PAIC_EP_RESERVED3!=""){
        			newPAIC_EP_RESERVED3 = params.PAIC_EP_RESERVED3;
        		}else{
        			newPAIC_EP_RESERVED3 = $("#jieduan").val();
        		}
        		newPAIC_EP_RESERVED1=newPAIC_EP_RESERVED1.replace(/<br>/g,"\n");
        		newPAIC_EP_RESERVED2=newPAIC_EP_RESERVED2.replace(/<br>/g,"\n");
        		newPAIC_EP_RESERVED3=newPAIC_EP_RESERVED3.replace(/<br>/g,"\n");
        	}
        	
        	// 转码
        	
        	// 赋值
        	pageData.ewn[xh].ewn_rea=params.PAIC_EP_RESERVED1;
        	pageData.ewn[xh].ewn_nco=params.PAIC_EP_RESERVED2;
        	pageData.ewn[xh].ewn_sum=params.PAIC_EP_RESERVED3;
        	pageData.ewn[xh].ewn_status=params.EP_TRK_STATUS;
        	
        	
        	// 将原始数据进行转码传到后台
        	
        	// 原始数据传给后台！
			params.PAIC_EP_RESERVED1=newPAIC_EP_RESERVED1;
			params.PAIC_EP_RESERVED2=newPAIC_EP_RESERVED2;
			params.PAIC_EP_RESERVED3=newPAIC_EP_RESERVED3;
			
			
        		isnew = params.FLAG7;
        		params.PAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3.replace(/\'/g,"’");
            	params.CONTENT_DESCR=params.CONTENT_DESCR.replace(/\'/g,"’");
            	params.PAIC_EP_RESERVED1=params.PAIC_EP_RESERVED1.replace(/\\/g,"/");
            	params.PAIC_EP_RESERVED2=params.PAIC_EP_RESERVED2.replace(/\\/g,"/");
            	params.PAIC_EP_RESERVED3=params.PAIC_EP_RESERVED3.replace(/\\/g,"/");
            	params.CONTENT_DESCR=params.CONTENT_DESCR.replace(/\\/g,"/");
            url = mpsurl+"/mobile/report/addReportEWN.do";
            var strewn = "[{'CONTENT_DESCR':'" + params.CONTENT_DESCR + "'," +
                "'EP_APPRAISAL_ID':'" + params.EP_APPRAISAL_ID + "'," +
                "'EP_TRK_STATUS':'" + params.EP_TRK_STATUS + "'," +
                "'FLAG7':'" + params.FLAG7 + "'," +
                "'MONTH_EP':'" + params.MONTH_EP + "'," +
                "'PAIC_EP_RESERVED1':'" + params.PAIC_EP_RESERVED1 + "'," +
                "'PAIC_EP_RESERVED2':'" + params.PAIC_EP_RESERVED2 + "'," +
                "'PAIC_EP_RESERVED3':'" + params.PAIC_EP_RESERVED3 + "'," +
                "'PAIC_EXPECTATION':'" + params.PAIC_EXPECTATION + "'," +
                "'SECTION_ID':'" + params.SECTION_ID + "'," +
                "'YEAR_EP':'" + params.YEAR_EP + "'}]";
            submitParams = {
                report : report_src,
                ewn_list : strewn
            }
            break;
    }
    if(saveFlag != "Y"&& isnew!="01"){
		$("#loading").show();
		ClearOkPf();// 去除点击按钮效果
	}
    if(isnew!="01"){
	    $.ajax({
	        type : "post",
	        url : url,
	        dataType : "json",
	        data :submitParams,
	        success : function(json) {
		    	if(saveFlag != "Y"){
		    		$("#loading").hide();
		            if (json.resultCode == "500600") {
		                //autoClosePrompt(json.HR_SSTEXT_TEXT);
		                // 新增关键计划，跳转页面
		                if(isnew=="01"){
		                	setTimeout(function(){
		                		// location.href="/mobile/kpi/kpi-todo.html?report_date="+report_date;
		                		var param = "report_date="+ report_date;
								gotoLocation("/mobile/kpi/kpi-todo.html",param);
		                	},2000);
		                }else{
		                	GetOkPf();// 得到点击效果！
		                }
		            } else {
		            	GetOkPf();// 得到点击效果！
		            	$("#loading").hide();
		            	if(json.resultCode=="500702" || json.resultCode=="500802" || json.resultCode=="500803"){
		            		var tourl = "/mobile/kpi/kpi-todo.html?report_date="+report_date;
		            		checkLogin(json.resultCode,tourl,json.resultMessage);
		            	}else{
		               		autoClosePrompt(json.resultMessage);
		                }
		            }
		    	}
		    	
	        },
	        error: function (xhr, textStatus, errorThrown) {
	        	if(saveFlag != "Y"){
		        	GetOkPf();// 得到点击效果！
		        	$("#loading").hide();
		            autoClosePrompt("网络连接异常");
	        	}
			}
	    });
    }
	    mScroll.refresh();
	}

// 监听页面输入变化
var changeFlag = false,oldText,newText; // 当页面改变的时候值为true
function pageIsChange(){
	$("#benyue,#xiayue,#jieduan").on("focus",function(){
		oldText = $(this).val();
//		ResizeTextarea(this,4);//处理文本框！！
		
	}).on("keyup",function(){
//		ResizeTextarea(this,4);//处理文本框！！
		newText = $(this).val();
		if(oldText == newText){
			changeFlag = false;
		}else{
			changeFlag = true;
		}
	}).on("blur",function(){
		newText = $(this).val();
		if(oldText == newText){
			changeFlag = false;
		}else{
			changeFlag = true;
		}
	}).on("input",function(){
		var _value = $(this).val();
		if(curItemType=="kpi"){
			if(_value.length>=254){
				setPromptForInput("输入字数不能超过254");
				$(this).val(_value.substr(0,254));
			}
		}else{
			if(_value.length>=500){
				setPromptForInput("输入字数不能超过500");
				$(this).val(_value.substr(0,500));
			}
		}
	})
	//验证标题
	
	
	var a=$("select").val(); 
	if(a!=undefined){
		if(a!=statuses){
			changeFlag = true;
		}else{
			changeFlag = false;
		}
	}
//	setTimeout(function(){
//		mScroll.refresh();
//	},200)
}
// 页面失效监听 Y是后台默认保存，N为用户保存
function timeoutListener(){
	setInterval(function(){
		if(changeFlag){
			evtHandler.saveNoyz("Y");
		}	
	  },600000);
}


function inputTitle(){//计算标题输入字数！
	$("#titleText").on("input",function(){
		var _value = $(this).val();
		if(_value.length>=245){
			setPromptForInput("输入字数不能超过245个字");
			$(this).val(_value.substr(0,245));
		}
	})
}
// 重新计算页面高度
// function goUpgoDomw(){
// $("#contentMain").css({
// "height":($(window).height()-$(".top-bar").height()-$(".footer-fixed").height()-100)+"px"
// });
// mScroll.refresh();
// }


$(function(){  
	$(window).resize(function(){
		mScroll.refresh();
	}); 
});

// 计算页面高度
function countPageHeight(){  
	winHeight = $(window).height();
	$("#wrap").height(winHeight);
	headerHeight = $("header.left-side-header").height();
	$("#iscroll").height(winHeight - headerHeight);  
}

function iscroll(){ 
	countPageHeight(); 
	myIscroll = new iScroll("iscroll",{bounce:false});
} 
/*
解决左侧菜单不能滑动 问题 20140410 begin
// 页面加载完后执行js代码
var $$ = function(func){
  var oldOnload =window.onload;
  if(typeof window.onload != 'function'){
      window.onload = func;
  }else{
      window.onload = function(){
          oldOnload();
          func();
      }
  }
}
// 在所有js执行后调用这里代码
$$(function(){   
	iscroll(); 
});
20140410 end
*/
$(function(){   
	iscroll(); 
});

function countSum (){
        var score = $("#scoreText").val() || 0;
        
        // 校验输入分数 begin
	    if(score.length>1&score.substring(0,1)=="0"){
			score = score.substring(1);
			$("#scoreText").val(score);
		}
		var t = /^((\d)|(\d{2})|(100))$/;
		if(!t.test(score)){
			score = score.replace(/\D/,"");
			score = score.substring(0,score.length-1);
			$("#scoreText").val(score);
			setPromptForInput("请输入0~100之间的数");
		}
}
function getDivLength(){
//	var doneLen=$("#doneText").find("br");
//	if(doneLen.size()<4){
//		$("#doneText").html($("#doneText").text()+"<br><br><br>")
//	}
	var doneLen=$("#doneText").height()
	if(doneLen<250){
		$("#doneText").css("height","250px");
	}
}